﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 

using OpenTK.Mathematics;
using OpenTK.Windowing.GraphicsLibraryFramework;


namespace OpenTK_Frame
{
    public class Camera
    {
        float speed = 1.5f;

        Vector3 position = new Vector3(0.0f, 0.0f, 3.0f);
        Vector3 front = new Vector3(0.0f, 0.0f, -1.0f);
        Vector3 up = new Vector3(0.0f, 1.0f, 0.0f);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="position"></param>
        /// <param name="front"></param>
        /// <param name="up"></param>
        public Camera(Vector3 _position, Vector3 _front, Vector3 _up)
        {
            Vector3 position = new Vector3(0.0f, 0.0f, 3.0f);
            Vector3 front = new Vector3(0.0f, 0.0f, -1.0f);
            Vector3 up = new Vector3(0.0f, 1.0f, 0.0f);

            Matrix4 view = Matrix4.LookAt(position, position + front, up);
        }

        public Camera(Vector3 cameraPos, Vector3 cameraTarget)
        {
            //Vector3.Zero  
            Vector3 cameraDirection = Vector3.Normalize(cameraPos - cameraTarget);
            Vector3 up = Vector3.UnitY;
            Vector3 cameraRight = Vector3.Normalize(Vector3.Cross(up, cameraDirection));
            Vector3 cameraUp = Vector3.Cross(cameraDirection, cameraRight);

            Matrix4 view = Matrix4.LookAt(cameraPos, cameraTarget, cameraUp);
        }


        public void CameraControllor()
        {

            if (!Focused) // check to see if the window is focused
            {
                return;
            }

            KeyboardState input =  Keyboard.GetState();

            //...

            if (input.IsKeyDown(Key.W))
            {
                position += front * speed; //Forward 
            }

            if (input.IsKeyDown(Key.S))
            {
                position -= front * speed; //Backwards
            }

            if (input.IsKeyDown(Key.A))
            {
                position -= Vector3.Normalize(Vector3.Cross(front, up)) * speed; //Left
            }
            if (input.IsKeyDown(Key.D))
            {
                position += Vector3.Normalize(Vector3.Cross(front, up)) * speed; //Right
            }
            if (input.IsKeyDown(Key.Space))
            {
                position += up * speed; //Up 
            }
            if (input.IsKeyDown(Key.LShift))
            {
                position -= up * speed; //Down
            }

        }


    }
}
